﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xrm.Sdk;

namespace NNAssociationTool.Plugin
{
    /// <summary>
    /// ServiceProvider Extension class
    /// </summary>
    static class IServiceProviderExtensions
    {
        /// <summary>
        /// Get TracingService
        /// </summary>
        /// <param name="serviceProvider">service provider</param>
        /// <returns>tracing service</returns>
        public static ITracingService GetTracingService(this IServiceProvider serviceProvider)
        {
            return serviceProvider.GetService(typeof(ITracingService)) as ITracingService;
        }
        /// <summary>
        /// Get PluginExecutionContext
        /// </summary>
        /// <param name="serviceProvider">service provider</param>
        /// <returns>IPluginExecutionContext</returns>
        public static IPluginExecutionContext GetPluginExecutionContext(this IServiceProvider serviceProvider)
        {
            return serviceProvider.GetService(typeof(IPluginExecutionContext)) as IPluginExecutionContext;
        }
        /// <summary>
        /// Get OrganizatinoServiceFactory
        /// </summary>
        /// <param name="serviceProvider">service provider</param>
        /// <returns>OrganizatinoServiceFactory</returns>
        public static IOrganizationServiceFactory GetOrganizatinoServiceFactory(this IServiceProvider serviceProvider)
        {
            return serviceProvider.GetService(typeof(IOrganizationServiceFactory)) as IOrganizationServiceFactory;
        }

    }
}
